package com.ls.controller;

import com.ls.dto.DepartmentDto;
import com.ls.service.DepartmentService;
import com.ls.utils.Status;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "DepartmentController",tags = "部门管理")
@RestController
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    @ApiOperation(value = "获取部门信息")
    @GetMapping("/dep/get")
    public Status getDepartments(Integer page,Integer pageSize){

        return departmentService.get(page,pageSize);
    }

    @ApiOperation(value = "条件获取部门信息")
    @GetMapping("/dep/getOfCondition")
    public Status getDepartmentOfCondition(String type, String content,Integer page,Integer pageSize){
        System.out.println(type+content+page+pageSize);
        if (type.equals("名称")){
            return departmentService.getOfName(content,page,pageSize);
        }else if (type.equals("地址")){
            return departmentService.getOfAddress(content,page,pageSize);
        }else {
            return new Status().setStatus(false).setMsg("不知道你干了啥ya~");
        }
    }

    @ApiOperation(value = "条件获取部门信息")
    @GetMapping("/dep/getOfStatus")
    public Status getDepartmentOfCondition(Integer status,Integer page,Integer pageSize){

        System.out.println("status:"+status);
        System.out.println("page:"+page);
        System.out.println("pageSize:"+pageSize);

        return departmentService.getOfStatus(status,page,pageSize);

    }

    @ApiOperation(value = "添加部门信息")
    @PostMapping(value = "/dep/add")
    public Status insertDepartment(@RequestBody DepartmentDto departmentDto){
        System.out.println(departmentDto);
        return departmentService.insertResult(departmentDto);
    }

    @ApiOperation(value = "修改部门状态")
    @PostMapping("/dep/updStatus")
    public Status updateStatus(@RequestBody DepartmentDto departmentDto){

        System.out.println("修改前id："+departmentDto.getDep_id()+"/t"+ " status："+departmentDto.getStatus());
        return departmentService.updateStatusResult(departmentDto.getDep_id(),departmentDto.getStatus());
    }

    @ApiOperation(value = "修改部门信息")
    @PostMapping("/dep/update")
    public Status updateDepartment(@RequestBody DepartmentDto departmentDto){
        System.out.println(departmentDto);
        return departmentService.updateResult(departmentDto);
    }

    @ApiOperation(value = "查看部门信息")
    @GetMapping("/dep/look")
    public Status lookDepartment(Integer depId){

        return departmentService.getDepartmentResult(depId);
    }

    @ApiOperation("获取部门列表")
    @GetMapping("/dep/getDepartment")
    public Status getDepartment(){
        return departmentService.getDepartmentResult();
    }
}
